'''
Created on 12.12.2009

@author: stud
'''
import Ice
import sys, traceback
from TkinterFrame import TkinterFrame
import Demo

class Client2(object):
    '''
    For Ice, Printer and Tkinter Instances
    ''' 

    __ic = None                     
    __printer= None                
    __tk = None   
                      

    def __init__(self):
        '''
        Constructor
        '''
        
    def startClient(self):
        '''
        Starting Ice, starting Tkinter
        '''
        
        self.startIce()
        self.__tk = TkinterFrame(self)
        self.__tk.loadTkinter()
    
    def startPrinter(self):
        '''
        Give Settings to printer for inizializing Multibodysys
        '''
#        self.__printer.setIP(self.__tk.getIpEntry())
#        self.__printer.setPort(int(self.__tk.getPortEntry()))
        self.__printer.setNumberOfBodies(int(self.__tk.getNumberOfBodiesEntry()))
        self.__printer.setLowerLimitMass(int(self.__tk.getMinMassEntry()))
        self.__printer.setUpperLimitMass(int(self.__tk.getMaxMassEntry()))
        self.__printer.setLowerLimitRadii(int(self.__tk.getMinRadiEntry()))
        self.__printer.setUpperLimitRadii(int(self.__tk.getMaxRadiEntry()))
        self.__printer.setMassCentralBody(float(self.__tk.getCentralMassStarEntryEntry()))
        self.__printer.setSpaceCircumferenceLowerLimit(int(self.__tk.getMinRangeEntry()))
        self.__printer.setSpaceCircumferenceUpperLimit(int(self.__tk.getMaxRangeEntry()))
        self.__printer.setDeltaT(86400)
        self.__printer.initRandomMultiBodySystem()
    
    def getPrinter(self):
        return self.__printer
   
    def startIce(self):
        '''
        Starting Ice, setting printer
        '''
    
        try:
            self.__ic = Ice.initialize(sys.argv)
            base = self.__ic.stringToProxy("SimplePrinter:default -p 10000")
            self.__printer = Demo.PrinterPrx.checkedCast(base)
            if not self.__printer:
                raise RuntimeError("Invalid proxy")
     
        except:
            traceback.print_exc()
            status = 1
        
            if self.__ic:
                #Clean up
                try:
                    self.__ic.destroy()
                except:
                    traceback.print_exc()
                    status = 1
                
                    sys.exit(status)
                    
   